import React from 'react';
import {Row, Col, Form, Tabs, message} from 'antd';
const R = require('ramda');
import OperatorConstant from "../../../utils/OperatorConstant";
import SingleDragger from "../../commons/SingleDragger";
const TabPane = Tabs.TabPane;
const FormItem = Form.Item;

export default Form.create({wrappedComponentRef: true})(class CusCredit extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            cusCredit: "",
            type: R.isNil(this.props.type) ? "" : this.props.type,
        };
    }


    resetUpload=(refs)=>{
        for(let i in refs){
            refs[i].resetUpload();
        }
    };

    handleResetFields = () => {
        this.resetUpload(this.refs);
        this.props.form.resetFields();
    }


    handleCustomer = () => {
        if(this.state.type ==OperatorConstant.add){
            return false;
        }else if(this.props.cstInfo.csttype === '1'){
            return true;
        }
    }


    handleSaveAttachment = () => {
        this.props.form.validateFields((errors, values) => {
            if (errors) return;

            let type =  'customerManage/update';
            let form ={};

            let customer = R.isNil(this.props.cstInfo) ? {} : this.props.cstInfo;
            form.cusCredit = R.isNil(this.refs.cusCredit.getUrl())?'':this.refs.cusCredit.getUrl();
            form.csttype = customer.csttype;
            form.id = this.props.cstid;
            this.props.dispatch({
                type: type,
                payload: {
                    form: form,
                    id:form.id,
                    onSuccess:()=>{
                        //this.resetUpload(this.refs);
                        // this.props.customerHandleCancel();
                    }
                },
            });


        });

    };




    render() {
        let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;
        let formItemLayout = {
            labelCol: { xs: { span: 24 }, sm: { span: 10 } },
            wrapperCol: { xs: { span: 24 }, sm: { span: 14 } }
        };

        if (!R.isNil(dataSource)) {
             this.state.cusCredit=dataSource.cusCredit;
        }


        let module="agreementInfo";

        return (
            <Form>
                <Tabs tabPosition={'top'}>
                    <TabPane tab="附件" key="1">
                        <Row>
                            <Col span={12} style={{display: this.handleCustomer() ?"none" : "inline-block" }}>
                                <FormItem {...formItemLayout} label={<span>信用证</span>} hasFeedback>
                                    <SingleDragger url={R.isNil(this.state.cusCredit)?'':this.state.cusCredit.url} dataSource={dataSource} ref="cusCredit" module={module} disabled={this.props.disabled}/>
                                </FormItem>
                            </Col>
                        </Row>
                    </TabPane>
                </Tabs>
            </Form>
        )
    }
})


// WEBPACK FOOTER //
// ./public/src/components/supplier/components/AgreementInfo.js